<form id="myEditForm" class="form-horizontal myEditForm" role="form">
    <div class="form-group">
        <label for="upgrade_project_id" class="col-lg-2 col-sm-2 control-label"><span style="color:red">*</span>所属项目</label>
        <div class="col-lg-10">
            <select id="upgrade_project_id" name="upgradePackage.upgrade_project_id" class="form-control" required>
            </select>
        </div>
    </div>
    <div class="form-group">
        <label for="second_name" class="col-lg-2 col-sm-2 control-label"><span style="color:red">*</span>子项目</label>
        <div class="col-lg-10">
            <input type="text" class="form-control" value="<%if(typeof second_name!='undefined'){%><%=second_name%><%}%>" required id="second_name" name="upgradePackage.second_name" placeholder="如：培养管理、学位管理">
        </div>
    </div>
    <div class="form-group">
        <label for="name" class="col-lg-2 col-sm-2 control-label"><span style="color:red">*</span>升级包名</label>
        <div class="col-lg-10">
            <input type="text" class="form-control" value="<%if(typeof name!='undefined'){%><%=name%><%}%>" required id="name" name="upgradePackage.name" placeholder="选择项目后，可自动生成默认包名">
        </div>
    </div>
    <div class="form-group">
        <label for="content" class="col-lg-2 col-sm-2 control-label"><span style="color:red">*</span>升级包内容说明</label>
        <div class="col-lg-10">
            <textarea rows="4" class="form-control" required id="content" name="upgradePackage.content" placeholder="500字内"><%if(typeof content!='undefined'){%><%=content%><%}%></textarea>
        </div>
    </div>
    <input type="hidden" value="<%if(typeof id!='undefined'){%><%=id%><%}%>" id="id" name="upgradePackage.id" placeholder="">
</form>

<script>
    $(function() {
        getUpgradeProjects();

        $('#upgrade_project_id').change(function() {
            getNewPackageName();
        });

        function getUpgradeProjects() {
            $.ajax({
                url: "/select/getUpgradeProjects?key=" + new Date().getTime(),
                cache: false, dataType: "json", type: "get",
                success: function(data) {
                    $('#upgrade_project_id').append('<option value="">...</option>');
                    for (var i = 0; i < data.datas.length; i ++) {
                        var d = data.datas[i];
                        $('#upgrade_project_id').append('<option value="'+ d.code +'">'+ d.name +'</option>');
                    }

                    <%if(typeof package_project_id!='undefined'&&package_project_id!=''){%>$('#upgrade_project_id').val('<%=package_project_id%>');<%}%>
                    getNewPackageName();
                }
            });
        }

        function getNewPackageName() {
            var packageProjectId = $('#upgrade_project_id').val() || '';
            if (packageProjectId == '') return;

            $.ajax({
                url: "/upgradePackage/getNewPackageName?packageProjectId=" + packageProjectId,
                cache: false, dataType: "json", type: "get",
                success: function(data) {
                    $('#name').val(data.name);
                    $('#second_name').focus();
                }
            });
        }

    });
</script>